<?php require_once ADMINVIEWPATH.'admin_header.php'; ?>
<?php require_once ADMINVIEWPATH.'admin_menu.php'; ?>
<style type="text/css">
    .bg_floating{
        position: relative;
        height: 100%;
        display: block;
    }
    .bg_floating:hover{
        background-color:#000;
        opacity:0.4;
        background:url("<?=STATICURL?>img/default.png") no-repeat;
        cursor:pointer;
    }
    .active{
        opacity:0.9;
    }
    .cover_btn {
        background: url("<?=STATICURL?>img/ico.png") no-repeat ;
        display: inline-block;
        position: absolute;
        right: 2px;
        top: 52px;
        width: 23px;        
        height: 23px;       
    }
</style>
<!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb">
                        <li>
                            <i class="fa fa-home"></i>
                            <a href="/luckydog/index">首页</a>
                        </li>
                        <li class="">
                            <a href="#">编辑兑换奖品</a>
                        </li>
                    </ul>
                </div>
                <!-- /Page Breadcrumb -->
                <!-- Page Body -->
                <div class="page-body">
                   <form class="form-horizontal" role="form">
                        <div class="row">
                                <div class="col-lg-12">
                                    <div class="widget">
                                        <div class="widget-header bordered-bottom bordered-blue">
                                            <span class="widget-caption">添加兑换奖品</span>
                                        </div>
                                        <div class="widget-body">
                                            <div id="horizontal-form">
                                                <form class="form-horizontal" role="form">
                                                <span style="color:red">（注：1.8件商品中奖概率之和为100&nbsp;&nbsp;&nbsp;&nbsp;2.图片建议上传png透明效果图片）</span>
                                                    <div class="row">
                                                        <div class="col-md-6">
                                                            <div class="pull-left" style="line-height: 30px;margin-left: 10px;margin-bottom: 20px;">标&nbsp;&nbsp;&nbsp;&nbsp;题:</div>
                                                            <div style="float: left; padding-left:10px;">
                                                                <input style="width: 400px;" class="form-control it_title" value="<?php echo $luckydrawdetail['title']?>" type="text" placeholder="请输入标题">
                                                            </div>
                                                            <div class="horizontal-space"></div>
                                                        </div>
                                                        <div class="col-md-6">
                                                            <div class="pull-left" style="line-height: 30px;margin-left: 10px;margin-bottom: 20px;">市场价:</div>
                                                            <div style="float: left; padding-left:10px;">
                                                                <input style="width: 400px;" class="form-control it_price" type="text" value="<?php echo $luckydrawdetail['price']?>" placeholder="请输入市场价">
                                                            </div>
                                                            <div class="horizontal-space"></div>
                                                        </div>
                                                        
                                                    </div>
                                                   <div class="row">
                                                        <div class="col-md-6 form-group">
                                                            <div class="pull-left"  style="line-height: 30px;margin-left: 25px;margin-bottom: 20px;">中奖概率:</div>
                                                            <div class="form-group pull-left" style="margin-left: 10px;">
                                                                <div class="input-group" style="width: 100px;">
                                                                    <input type="text"  class="form-control it_chance" value="<?=$luckydrawdetail['chance']?>" placeholder="请输入中奖概率">
                                                                    <span class="input-group-addon">%</span>
                                                                </div>
                                                            </div>
                                                            <div style="color:red;line-height: 30px;margin-left: 25px;margin-bottom: 20px;" class="pull-left">当前中奖概率填写范围0-<?=$mychance?></div>
                                                        </div>

                                                        <div class="col-md-6">
                                                            <label>自取</label>
                                                            <label>
                                                                <input  <?php if($luckydrawdetail['gettype'] == "1"):?>checked=""<?php endif;?>  class="checkbox-slider toggle colored-blue gettype" type="checkbox">
                                                                <span class="text"></span>
                                                            </label>
                                                            <div class="horizontal-space"></div>
                                                            <label>空奖</label>
                                                            <label>
                                                                <input  <?php if($luckydrawdetail['isempty'] == "1"):?>checked=""<?php endif;?>  class="checkbox-slider toggle colored-blue isempty" type="checkbox">
                                                                <span class="text"></span>
                                                            </label>
                                                            <div class="horizontal-space"></div>
                                                        </div>
                                                    </div>
                                                   <div class="row">
                                                       <div class="col-md-6">
                                                            <div class="pull-left" style="line-height: 30px;margin-left: 10px;margin-bottom: 20px;">库&nbsp;&nbsp;&nbsp;&nbsp;存:</div>
                                                            <div style="float: left; padding-left:10px;">
                                                                <input style="width: 400px;" class="form-control it_stock" type="text" value="<?php echo $luckydrawdetail['stock']?>" placeholder="请输入库存量">
                                                            </div>
                                                            <div class="horizontal-space"></div>
                                                        </div>
                                                    </div>
                                                    <div class="row address" style="display: <?php if($luckydrawdetail['gettype'] == "1"):?>block<?php else:?>none<?php endif;?>">
                                                        <div class="col-md-3">
                                                            <select class="form-control it_province">
                                                                <option value="0">-----请选择省----</option>
                                                                <?php foreach($provinceList as $pro):?>
                                                                <option  value="<?= $pro['id']?>"  <?php if($luckydrawdetail['provinceid'] == $pro['id']):?>selected<?php endif;?>>
                                                                    <?=$pro['name']?>
                                                                </option>
                                                                <?php endforeach;?>
                                                            </select>
                                                            <div class="horizontal-space"></div>
                                                        </div>
                                                        <div class="col-md-3">
                                                            <select class="form-control it_city">
                                                                <option value="0">-----请选择市----</option>
                                                                <?php foreach($cityList as $city):?>
                                                                <option   value="<?= $city['id']?>"  <?php if($luckydrawdetail['cityid'] == $city['id']):?>selected<?php endif;?>>
                                                                    <?=$city['name']?>
                                                                </option>
                                                                <?php endforeach;?>
                                                            </select>
                                                            <div class="horizontal-space"></div>
                                                        </div>
                                                        <div class="col-md-6">
                                                            <div class="pull-left" style="line-height: 30px;margin-left: 10px;margin-bottom: 20px;">详细地址:</div>
                                                            <div style="float: left; padding-left:10px;">
                                                                <input style="width: 400px;" class="form-control it_area" type="text" value="<?php echo $luckydrawdetail['area']?>" placeholder="请输入详细地址">
                                                            </div>
                                                            <div class="horizontal-space"></div>
                                                        </div>
                                                        
                                                    </div>
                                                    
                                                    
                                                    <div class="recent-posts" style="float: left">
                                                        <li class="cp_photo_con" style="list-style-type:none;">
                                                            <p ><span  id="J_morepic_upload"></span></p>
                                                        </li>
                                                    </div>
                                                    <fieldset> <legend>奖品封面图上传</legend>
                                                    <div class="widget-content">
                                                        <div class='clearfix' style="margin-top:15px;">
                                                            <div id="container" style="float: left">
                                                                <a id="selectfiles" href="javascript:void(0);" class='btn'>选择图片</a>
                                                                <a id="postfiles" href="javascript:void(0);" class='btn'>开始上传</a>
                                                            </div>
                                                            <span id="console"></span>
                                                            <?php if(!empty($luckydraw_img_list)):?>
                                                            <span id = "ossfile"  style="">
                                                            <?php foreach ($luckydraw_img_list as $key => $row) :?>
                                                                <div style="position:relative;float:right;margin-left:5px;">
                                                                <div class="bg_floating" style="position:relative;float:right;margin-left:5px;">
                                                                    <img class="uploadpic" data_id="<?=$row['id']?>" img-original="<?=$row['imgurl']?>" src="<?=OSSHOST.$row['imgurl']?>" width="120px" height="80px" alt="pic"/>
                                                                    <?php if($row["is_default"]):?><em class="cover_btn J_cover_btn"></em><?php endif;?>
                                                                </div><br />
                                                                <a class="del_pic" data_id="<?=$row['id']?>" style="margin-left:40px;" href="javascript:void(0);">删除</a>
                                                                </div>
                                                            <?php endforeach;?>
                                                            </span>
                                                            <?php else :?>
                                                            <span id="ossfile" style="position:relative;float:right;margin-left:5px">
                                                            </span>
                                                            <?php endif;?>
                                                        </div>
                                                    </div>
                                                    </fieldset>
                                                    <hr>
                                                    <div class="row">
                                                        <div class="col-md-12">
                                                            <label >简介/参数</label>
                                                                <textarea class="form-control summary" id="summary"  placeholder="summary" style="height:300px;width:90%;"><?php echo $luckydrawdetail['summary']?></textarea>
                                                            <div class="horizontal-space"></div>
                                                        </div>
                                                    </div>
                                                    <div>
                                                        <span id="js_submit" class="btn btn-default">提 交</span>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                    </form>
                </div>
            </div>
            <!-- /Page Body -->
        </div>
        <!-- /Page Content -->

<?php require_once ADMINVIEWPATH.'admin_footer.php'; ?>
<script src="<?= STATICURL; ?>js/jquery.min.js"></script>
<script src="<?= STATICURL; ?>layer/layer.js"></script>
<script src="<?= STATICURL; ?>kindeditor/kindeditor.js"></script>
<script type="text/javascript" src="<?=STATICURL;?>js/latest.js"></script>
<script type="text/javascript" src="<?=STATICURL;?>js/plupload-2.1.2/plupload.full.min.js"></script>
<script type="text/javascript" src="<?=STATICURL;?>js/item-upload.js"></script>
<script>
KindEditor.ready(function(K) {
    window.editor = K.create('#summary');
});
var js_stock = $(".it_stock").val();
        $(".it_stock").bind({
                keyup:function(){
                     var txt = $('.it_stock').val();
                     var reg = /^[\d]+$/;
                     if(!reg.test(txt) ){
                            $(this).val('');
                     }
                },
                focus:function(){
                    if ($(this).val() == 0){
                        $(this).val('');
                    }
                },
                blur:function(){
                    if ($(this).val() == ''){
                        $(this).val(js_stock);
                    }                   
                }
        });
$(".it_province").change(function(){
            var privinceid = $(this).val();
            $.post("<?=BASEURL?>luckydog/news/cityList",{privinceid:privinceid},function(data){
                // console.log(data);
                var _option = '';
                $.each(data,function(index,item){
                    _option += '<option value="'+item.id+'">'+item.name+'</option>';
                });
                $(".it_city").html(_option);
            },'json');
        });
$(".del_pic").live("click",function(){
        var imgsource = $(this).parent().attr("d-original");
        var id = $(this).attr("data_id");
        $.post('/luckydog/luckydraw/del_pic', {'imgsource':imgsource,id:id}, function(res) {
            
        });
        $(this).parent().remove();
    });

$(".bg_floating").live("click",function(){
    var tmp_html = '<em class="cover_btn J_cover_btn"></em>';
    $(".cover_btn").remove();           
    $(this).append(tmp_html);
    if($(".bg_floating").hasClass("active")){
        $(".bg_floating").removeClass("active");    
    }
    $(this).addClass("active");
});
$(".gettype").change(function(){
    var gettype = $(".gettype").prop("checked");
        if(gettype == true)
        {
            $(".address").css("display","block");
        }else{
            $(".address").css("display","none");
        }
});
$(document).ready(function(){
    $("#js_submit").on("click",function(){

        editor.sync();//Js获取值时前面添加
        var categoryid = $(".it_categoryid").val();
        var title = $(".it_title").val();
        var price = $(".it_price").val();
        var chance = $(".it_chance").val();
        var stock = $(".it_stock").val();
        var exchangepoints = $(".it_exchangepoints").val();
        var summary = $("#summary").val();
        if (title == ""){
            layer.msg("标题不能为空");$(".it_title").focus();return;
        }
        if (price == ""){
            layer.msg("市场价");$(".it_price").focus();return;
        }    
        if (exchangepoints == ""){
            layer.msg("兑换积分");$(".it_exchangepoints").focus();return;
        }      
        if (chance == ""){
            layer.msg("请填写中奖概率");$(".it_chance").focus();return;
        }    
        var  mychance = <?=$mychance?>;
        if(chance > mychance)
        {
            layer.msg("本奖品积分这是必须在0-"+mychance+"之间");
            return false;
        }

        var original_arr = new Array();
        var default_arr = new Array();
        var ids_arr = new Array();
        $(".uploadpic").each(function(index){
            if(index === 0){
                    default_arr.push("1");
            }else{
                default_arr.push("0");
            }
            original_arr.push($(this).attr("img-original"));
            ids_arr.push($(this).attr("data_id"));
        });
        if(original_arr.length<=0){
            layer.msg("请上传奖品封面图片");
            return;
        }
        var gettype = $(".gettype").prop("checked");
            if(gettype == true)
            {
                gettype = 1;
            }else{
                gettype = 2;
            }
        var isempty = $(".isempty").prop("checked");
        if(isempty)
        {
            isempty = 1;
        }else{
            isempty = 0;
        }
        var provinceid = $(".it_province").val();
        var area = $(".it_area").val();
        var cityid = $(".it_city").val();
        var id = "<?php echo $luckydrawdetail['id']?$luckydrawdetail['id']:0; ?>";
        var _execute = "do_add";
        if(id > 0){
            _execute = "do_edit";
        }

        $.post("/luckydog/luckydraw/"+_execute, {stock:stock,chance:chance,isempty:isempty,gettype:gettype,area:area,provinceid:provinceid,cityid:cityid,id:id,title:title,price:price,exchangepoints:exchangepoints,summary:summary,original_arr:original_arr,default_arr:default_arr,ids_arr:ids_arr}, function(data) {
            if (data.status) {
                layer.msg(data.message);
                window.location.href="/luckydog/luckydraw";
            }else{
                layer.msg(data.message);
            }
        }, "json");
    });  
});
</script>






